package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-05-21
 * Time: 11:33
 */
public class Demo5 {
    public static void main(String[] args) throws InterruptedException {
        //lambda表达式
        /**
         * 创建了一个匿名的函数式接口的子类，并且创建出对应的实例并且重写了里面的方法(编译器做的事情)
         */
        //这里thread接收的相当与传入runnable参数
        Thread thread = new Thread(() -> {
            while (true) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();

        while (true) {
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}
